<template>
	<view class="classlist">
		<view class="content">
			<navigator :url="'/pages/preview/preview?id='+item._id+'&name='+className"  class="item" v-for="item in classList" 
			:key="item._id"
				 >
				<image :src="item.smallPicurl" mode="aspectFill"></image>
				
			</navigator>
		</view>
		
	</view>
</template>

<script setup>
	
	import { ref } from 'vue';
	import {onLoad,onReachBottom} from '@dcloudio/uni-app'
	import { apiGetClassList,apiUserWallList} from '../../api/apis';
	import {gotoHome} from "@/utils/common.js"
const queryParams={
	pageNum:2,
	pageSize:12
}
const noData=ref(false)
const className=ref(null)
	onLoad((e)=>{
		
		let {id=null,name=null,type=null}=e
		if(type){
			queryParams.type=type
		}else{
			
			if(id){
				queryParams.classid=id
			}else{
				gotoHome()
			}
		}
		
		className.value=name
		console.log("className",className.value)
		
		
		uni.setNavigationBarTitle({
			title:name
		})
			getClassList()
	})
	
	onReachBottom(
	(e)=>{
		if (noData.value) return
		queryParams.pageNum++;
		
		
		getClassList()
	}
	)
	const classList=ref([])
	async function getClassList(){
		let res;
		// console.log("获取我的下载",queryParams.type)
		if(queryParams.classid){
			
			 res =await apiGetClassList(
				
				// classid:"6524a48f6523417a8a8b825d"
				// classid:queryParams.classid
				queryParams
			);//返回的是一个promise对象
		}
		if(queryParams.type){
			console.log("获取我的下载queryParams",queryParams)
		res =await	apiUserWallList(queryParams);
		console.log("获取我的下载res",res)
		}
		
		
		classList.value= [...classList.value,...res.data]
		console.log(classList.value)
		if(queryParams.pageSize>res.data.length) noData.value=true;
		uni.setStorageSync("storageClassList",classList.value)
	
	}

	
	

</script>

<style lang="scss" scoped>
.classlist{
	.content{
		display: grid;
		grid-template-columns: repeat(3,1fr);
		gap:5rpx;
		padding:5rpx;
		.item{
			height: 440rpx;
			image{
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
}
</style>
